#include <TGS/MapControl2.0/CadRenderer.h>
#include "../dxf/DxfRenderModel.h"
#include "../dxf/DxfReader.h"

namespace TGS{
namespace MapControl{


CadRenderer::CadRenderer(const QString& filePath)
	: _dxfRenderModel(nullptr)
{
	resetFile(filePath);
}

CadRenderer::CadRenderer()
	: _dxfRenderModel(new DxfRenderModel())
{

}


CadRenderer::~CadRenderer(void)
{
	if(nullptr != _dxfRenderModel)
	{
		delete _dxfRenderModel;
		_dxfRenderModel = nullptr;
	}
}

void CadRenderer::render( RenderContext* renderContext )
{
	_dxfRenderModel->render(renderContext);
}

TGS::GeoMath::Envelope CadRenderer::getEnvelope() const
{
	if(!isVisible()) return Envelope();

	return _dxfRenderModel->getEnvelope();
}

void CadRenderer::resetFile( const QString& filePath )
{
	if(nullptr != _dxfRenderModel)
	{
		delete _dxfRenderModel;
	}

	_dxfRenderModel = DxfReader::read(filePath);
}

bool CadRenderer::haveData() const
{
	return _dxfRenderModel->haveData();
}

}//MapControl
}//TGS